/*
 * Project: SmartWard
 * Package: com.ruoyi.ichen.app
 * File: GoodsController
 * Date: 2020-2-13 14:12
 * Version: V1.0
 * Copyright © 2018 - 2019 YESOFT CHINA, Inc. All Rights Reserved.
 */
package com.ruoyi.ichen.app.controller;

import com.ruoyi.ichen.app.service.GoodsService;
import com.ruoyi.ichen.base.rest.RestDTO;
import com.ruoyi.ichen.entity.IGoods;
import com.ruoyi.ichen.entity.dto.GoodsSearchDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName: GoodsController
 * @Description: 商品信息
 * @Author chenhuanghua
 * @Date 2020-2-13 14:12
 * @Version V1.0
 */
@Controller
@RequestMapping("/app/goods")
public class GoodsController {

    @Autowired
    GoodsService goodsService;

    @PostMapping("/add")
    @ResponseBody
    public RestDTO Addgoods(@RequestBody IGoods goods){
        try {
            goodsService.save(goods);
            return new RestDTO(true, "添加成功");
        }catch (Exception e){
            return new RestDTO(false,"添加失败");
        }
    }

    /**
     * 获取商品的信息统计
     * @param name
     * @param startDate
     * @param endDate
     * @return
     */
    @PostMapping("/report")
    @ResponseBody
    public RestDTO findGoodsReport(@RequestBody GoodsSearchDto dto){
        try {
            List<IGoods> list = goodsService.findGoodsReport(dto);
            return new RestDTO(true, list);
        }catch (Exception e){
            return new RestDTO(false,"查询失败，请联系管理员");
        }
    }

}